import { HTTP_SUCCESS_CODE } from '@/constants'

/**
 * 判断 HTTP 状态码是否为成功状态
 * @param code HTTP 状态码
 * @returns 是否为成功状态
 */
export function isHttpSuccess(code: number): boolean {
  return code >= HTTP_SUCCESS_CODE && code < 300
}

/**
 * 判断响应是否为成功状态
 * @param response API 响应对象
 * @returns 是否为成功状态
 */
export function isResponseSuccess(response: any): boolean {
  if (!response) return false
  const code = response.code || response.status
  return isHttpSuccess(code)
}
